package com.harzone.commons.search.impl.statement;

import com.harzone.commons.search.statement.Delete;
import com.harzone.commons.search.visitor.DeleteVisitor;


public class DeleteParser extends BaseParser implements DeleteVisitor{

	boolean condition = false;
	
	
	
	public DeleteParser(Delete delete) {
		this.visit(delete);
	}
	
	
	@Override
	public void visit(Delete delete) {
		if(delete.hasWhere()){
			WhereParser w = new WhereParser(delete.getWhere());
			w.parse(query);
			if(!w.isHasMethod()){
				String[] strs = query.getFilterQueries();
				StringBuilder sb = new StringBuilder();
				int index1 = 0;
				for (String string : strs) {
					if(index1>0){
						sb.append(" AND ");
					}
					sb.append(string);
					index1 ++;
				}
				query.setQuery(sb.toString());
			}
			condition = true;
		}
	}

	
	public boolean hasCondition(){
		return condition;
	}
	
}
